<?php

/* * 注意此文档为UTF-8的编码.
 * Created on 2010-6-29
 *
 * @author EXT <isrn@qq.com>
 *
 */
include ('../../includes/global.php');
include ('../global.php');
include ("../power.php");
$dbcfg = Sys::Gp(array('dbcfg', 'sevenel'));
$donotrender = array('htmleditor', 'fckeditor', 'password', 'hidden');

function grv($type, $blm, $dvalue = false) {
    //print_r($type);
    if ($dvalue !== false && isset($dvalue)) {
        return $dvalue;
    } else {
        switch ($type) {
            case 'function': {
                    $a = explode('#', $blm);
                    return $a[0]($a[1]);
                    break;
                }
            case '$_GET': {
                    return $_GET[$blm];
                    break;
                }
            case '$_SESSION': {
                    return $_SESSION[$blm];
                    break;
                }
            case '$_POST': {
                    return $_POST[$blm];
                    break;
                }
            case '$_COOKIE': {
                    return $_COOKIE[$blm];
                    break;
                }
            case '$_SERVER': {
                    return $_SERVER[$blm];
                    break;
                }
            case '$_ENV': {
                    return $_ENV[$blm];
                    break;
                }
            case '$_FILES': {
                    return $_FILES[$blm];
                    break;
                }
            case '0': {
                    return $blm;
                    break;
                }
            case '1': {
                    break;
                }
            default: {
                    return $blm;
                    break;
                }
        }
    }
}

switch ($_REQUEST['op']) {
    case 'add': {
            if ($_SESSION[userinfo][rcfg] == 4) {
                $cab = "and fname!='tj2' and fname!='tj3'";
            } else {
                $cab = "";
            }
            $tree_id = $_GET['tid'];
            Tr($_GET['tid'], 'tid');
            Tr($_GET['bdtid'], 'bdtid');
            Tr($_GET['bdid'], 'bdid');
            $field = Dgd(array(
                'db' => 'd_sevenel',
                'cd' => "tid = $tree_id " . $cab . " and del!=1 order by px asc",
                'tn' => "fld"
                    ));
            $tree = Dgd(array(
                'db' => 'd_sevenel',
                'cd' => "id = $tree_id",
                'tn' => "tree",
                'limit' => 1
                    ));
            $tname = gettabname($tree['table'], $dbcfg['prefix'], true);
            Tr($tname, 'tname');
            if ($_GET['id']) {
                Tr($_GET['id'], 'id');
                $fdada = Dgd(array(
                    'db' => 'd_sevenel',
                    'cd' => " id = '" . $_GET['id'] . "' and del != '1' ",
                    'tn' => "$tname",
                    'limit' => 1
                        ));
                Tr($fdada['gid'], 'gid');
                Tr(preg_replace("/[\s]{2,}/", "", $fdada['lg']), 'lg');
            }

            /**
             * 动态级联 使用
             */
            foreach ($field as $arrow => $value) {
                if ($value['cfg'] != '') {
                    $config_tmp = json_decode($value['cfg'], true);
                    if ($config_tmp['dtjl']['kg'] && $config_tmp['dtjl']['fjzd'] != '') {
                        //保存开启级联的字段
                        $dtjl[$config_tmp['dtjl']['jlzd']][] = array('field' => $value['fname'], 'field2' => $config_tmp['dtjl']['fjzd']);
                        //需要处理默认值的字段
                        $dtjl_default[$value['fname']] = array('field' => $config_tmp['dtjl']['jlzd'], 'field2' => $config_tmp['dtjl']['fjzd']);
                    }
                }
            }
            foreach ($field as $arrow => $value) {
                $back = is_odd($arrow + 1) ? "itemCls:'hang'," : "";
                if ($value['cfg'] != '') {
                    $config = json_decode($value['cfg'], true);
                } else {
                    $config = '';
                }
                $config['sclj'] || $config['sclj'] = 'pic';
                /* 			if($config!=''){foreach($config  as $key=>$v){
                  $config[$key]=adxx($v);
                  }}
                 */ $config['STR'] = str_replace("\r", "", $config['STR']);
                $config['STR'] = str_replace("\n", "", $config['STR']);
                $config['STR'] = str_replace("\t", "", $config['STR']);
                switch ($value['type']) {
                    case 'hidden': {
                            $js[] = "{
							xtype: 'hidden',
								value:\"" . (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']]))) . "\",
								" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							name: '" . $value['fname'] . "'
							}";
                            break;
                        }
                    case 'textfield': {
                            $js[] = "{
							xtype: 'textfield',
							value:\"" . (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']]))) . "\",
							fieldLabel:'" . $value['name'] . "',
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							" . (($value['width']) ? ("width:'" . $value['width'] . "px',") : ("grow:true,growMin:68,growMax:300,")) . "
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							" . (($config['readonly']) ? ("readOnly:'true',") : ("")) . "
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							" . $back . "
							name: '" . $value['fname'] . "'
							}";
                            break;
                        }
                    case 'colorpickerfield': {
                            $default_val = (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']])));
                            $default_val = $default_val == '' ? '000000' : $default_val;
                            $js[] = "{
							xtype: 'colorpickerfield',
							value:\"" . $default_val . "\",
							fieldLabel:'" . $value['name'] . "',
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							" . (($value['width']) ? ("width:'" . $value['width'] . "px',") : ("grow:true,growMin:68,growMax:300,")) . "
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							" . (($config['readonly']) ? ("readOnly:'true',") : ("")) . "
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							" . $back . "
							name: '" . $value['fname'] . "'
							}";
                            break;
                        }
                    case 'password': {
                            $js[] = "{
							xtype: 'textfield',
							value:\"" . (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']]))) . "\",
							fieldLabel:'" . $value['name'] . "',
							inputType: 'password',
							id: '" . $value['fname'] . "',
							width:'150',
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							" . $back . "name: '" . $value['fname'] . "'
							}";
                            if ($value['yxwk']) {
                                $js[] = "{
							xtype: 'textfield',
							value:\"" . (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']]))) . "\",
							fieldLabel:'确认" . $value['name'] . "',
							inputType: 'password',
							vtype: 'password',
							width:'150',
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							initialPassField: '" . $value['fname'] . "',
							" . $back . "name: '" . $value['fname'] . "-cfrm'
							}";
                                $plugurl[] = '/Plug-in/ext/adv-vtypes.js';
                            }
                            break;
                        }
                    case 'fileup': {
                            $zs = '';
                            $qk = '';
                            //默认路径
                            $config['sclj'] || $config['sclj'] = 'pic';
                            if ($fdada[$value['fname']] != '') {
                                $dvalue = array(0 => array('rar', 'zip', 'tar', '.tz'),
                                    1 => array('jpg', 'jpeg', 'gif', 'png', 'bmp'),
                                    2 => array('mp3', 'mp4', 'avi', 'wmv', 'mid', '.rm', 'mvb', 'mov', 'wma', 'wav'),
                                    3 => array('doc', 'xls', 'txt', 'ocx', 'lsx', 'ppt', 'pdf', 'chm'),
                                    4 => array('doc', 'xls', 'txt', 'ocx', 'lsx', 'ppt', 'pdf', 'chm', 'mp3', 'mp4', 'avi', 'wmv', 'mid', '.rm', 'mvb', 'mov', 'wma', 'wav', 'jpg', 'gif', 'png', 'bmp', 'rar', 'zip', 'tar', '.tz')
                                );
                                //$otype = substr(strtolower($fdada[$value['fname']]), -3);
                                $otype = trim(end(explode('.', strtolower($fdada[$value['fname']]))));
                                if (in_array($otype, $dvalue[0])) {
                                    $zs = "<a href=\"/uplods/{$config['sclj']}/" . $fdada[$value['fname']] . "\" target=\'_blank\'><img src=\"../img/archive.png\">下载[Download]</a>";
                                }
                                if (in_array($otype, $dvalue[1])) {
                                    if ($config['sypic'] == 1 || $config['sytxt'] == 1) {
                                        $zs = "<img id=\"annex-{$value['fname']}\" src=\"/uplods/sytp/" . $fdada[$value['fname']] . "\" >";
                                    } else {
                                        $imagesize = getimagesize("../../uplods/{$config['sclj']}/{$fdada[$value['fname']]}");
                                        $max_height = $imagesize[1] > 100 ? 100 : $imagesize[1];
                                        $zs = "<img id=\"annex-{$value['fname']}\" src=\"/uplods/{$config['sclj']}/" . $fdada[$value['fname']] . "\" height=\"{$max_height}\" >";
                                    }
                                }
                                if (in_array($otype, $dvalue[2])) {
                                    $zs = "<a href=\"/uplods/{$config['sclj']}/" . $fdada[$value['fname']] . "\" target=\'_blank\'><img src=\"../img/film_link.png\">下载[Download]</a>";
                                } else if (in_array($otype, $dvalue[3])) {
                                    $zs = "<a href=\"/uplods/{$config['sclj']}/" . $fdada[$value['fname']] . "\" target=\'_blank\'><img src=\"../img/report_word.png\">下载[Download]</a>";
                                }
                                $qk = " <a href=\"javascript:void(0)\"  onclick=qkzd(\"" . $fdada['id'] . "\",\"" . $value['fname'] . "\",this) ><img src=\"../img/001_02.gif\">清空此附件</a>";
                            }
                            $js[] = "{
							xtype: 'textfield',
							fieldLabel:'" . $value['name'] . "',
							inputType: 'file',
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							width:'150',
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							" . $back . "name: '" . $value['fname'] . "'
							},{" . $back . "html:'<div style=\"float:left;width:300px;\" align=center>" . $zs . "" . $qk . "</div>'}";
                            break;
                        }
                    case 'textarea': {
                            $js[] = preg_replace("/[\s]{2,}/", "", "{
							xtype: 'textarea',
							value:\"" . (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']]))) . "\",
							fieldLabel:'" . $value['name'] . "',
							grow:true,
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							" . (($value['width']) ? ("width:'" . $value['width'] . "px',") : ("width:'400px',")) . "
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							" . (($config['readonly']) ? ("readOnly:'true',") : ("")) . "
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							" . $back . "
							name: '" . $value['fname'] . "'
							}");
                            break;
                        }
                    case 'htmleditor': {
                            $js[] = preg_replace("/[\s]{2,}/", "", "{
							xtype: 'htmleditor',
							value:\"" . (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']]))) . "\",
							fieldLabel:'" . $value['name'] . "',
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							" . (($value['width']) ? ("width:" . $value['width'] . ",") : ("anchor:'98%',")) . "
							" . (($config['height']) ? ("height:" . $config['height'] . ",") : ("")) . "
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							" . $back . "
							name: '" . $value['fname'] . "'
							}");
                            break;
                        }
                    case 'fckeditor': {
                            $js[] = preg_replace("/[\s]{2,}/", "", "{
						xtype:\"textarea\",
						" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
						value:\"" . (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']]))) . "\",
						" . (($value['width']) ? ("width:" . $value['width'] . ",") : ("anchor:'98%',")) . "
						" . (($config['height']) ? ("height:" . $config['height'] . ",") : ("height:300,")) . "
						fieldLabel:'" . $value['name'] . "',
						" . $back . "
						listeners:{
						     focus:function(f){
								 				var myMask = new Ext.LoadMask(Ext.getBody(), {msg:'请等待'});
												myMask.show();
												var w=f.getSize();
												   fckEditor = new FCKeditor('" . $value['fname'] . "') ;
												   fckEditor.Height=" . (($config['height']) ? ($config['height']) : (300)) . ";
												   fckEditor.Width=" . (($value['width']) ? ($value['width']) : (800)) . ";
												fckEditor.SkinPath = '/Plug-in/fck/editor/skins/silver/' ;
												fckEditor.BasePath = '/Plug-in/fck/' ;
												fckEditor.Config['ToolbarStartExpanded'] = " . (($config['zhed']) ? ("false") : ('true')) . ";
												" . (($config['STR']) ? ($config['STR']) : ("")) . "
												fckEditor.ReplaceTextarea() ;
												myMask.hide();
						                     }
						                   },
						name: '" . $value['fname'] . "'
						}");
                            $fckplugin.="try{var fckobj_temp = FCKeditorAPI.GetInstance('" . $value['fname'] . "');
										 fckobj_temp.UpdateLinkedField();}catch(err){
														};";
                            $plugurl[] = '/Plug-in/fck/fckeditor.js';   // fckEditor.ReplaceTextarea() ;
                            break;
                        }
                    case 'kindeditor': {
                            $yuan = array("</script>", "vegetables", "fiber");
                            $tyuan = array("<\/script>", "beer", "ice cream");

                            $js[] = preg_replace("/[\s]{2,}/", "", "{
						xtype:\"textarea\",
						id:'" . $value['fname'] . "',
						" . $back . "
						value:\"" . (grv($value['qzfs'], $value['blm'], str_replace($yuan, $tyuan, adxx(preg_replace("'([\r\n])[\s]+'", "", $fdada[$value['fname']]))))) . "\",
						" . (($value['width']) ? ("width:" . $value['width'] . ",") : ("anchor:'98%',")) . "
						" . (($config['height']) ? ("height:" . $config['height'] . ",") : ("height:300,")) . "
						fieldLabel:'" . $value['name'] . "',
						listeners:{
							   render:function(f){
													try{
                                                        KEeditor{$value['fname']}='';
                                                        KindEditor.ready(function(K) {
                                                                KEeditor{$value['fname']} = K.create('#{$value['fname']}', {
                                                                        resizeType : 2,
                                                                        " . (($config['STR']) ? ($config['STR']) : ("")) . "
                                                                        width:" . (($value['width']) ? ("'" . $value['width'] . "px'") : ('70%')) . ",
                                                                        height:" . (($config['height']) ? ("'" . $config['height'] . "px'") : ("'300px'")) . "
                                                                });
                                                        });
                                                    }catch(err){
															};
													}
						                   },

						name: '" . $value['fname'] . "'
						}");
                            $fckplugin.="KEeditor{$value['fname']}.sync();";
                            $plugurl[] = '/Plug-in/kind/kindeditor.js';   // fckEditor.ReplaceTextarea() ;
                            break;
                        }
                    case 'datefield': {
                            if (is_numeric($fdada[$value['fname']])) {
                                $fdada[$value['fname']] = date($config['zqgs'], $fdada[$value['fname']]);
                            }
                            $js[] = "{
							xtype: 'datefield',
							" . $back . "
							value:\"" . (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']]))) . "\",
							fieldLabel:'" . $value['name'] . "',
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							" . (($value['width']) ? ("width:" . $value['width'] . ",") : ("")) . "
							disabledDays :[" . @implode(',', $config['pbxq']) . "],
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							" . (($config['zwxs']) ? ("readOnly:'true',") : ("")) . "
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							" . (($config['zqgs']) ? ("format:'" . $config['zqgs'] . "',") : ("")) . "
							name: '" . $value['fname'] . "'
							}";
                            if ($config['zwxs'] == 1) {
                                $plugjs[] = 'Date.dayNames = ["日", "一", "二", "三", "四", "五", "六"];
						    if (Ext.DatePicker) {
						        Ext.apply(Ext.DatePicker.prototype, {
						            todayText: "今天",
						            minText: "日期在最小日期之前",
						            maxText: "日期在最大日期之后",
						            disabledDaysText: "",
						            disabledDatesText: "",
						            monthNames: Date.monthNames,
						            dayNames: Date.dayNames,
						            nextText: "下月 (Control+Right)",
						            prevText: "上月 (Control+Left)",
						            monthYearText: "选择一个月 (Control+Up/Down 来改变年)",
						            todayTip: "{0} (Spacebar)",
						            okText: "确定",
						            cancelText: "取消",
						            format: "y年m月d日"
						        });
   					}';
                            }
                            break;
                        }
                    case 'my97': {
                            if (is_numeric($fdada[$value['fname']])) {
                                $fdada[$value['fname']] = date($config['zqgs'], $fdada[$value['fname']]);
                            }
                            $js[] = "{
							xtype: 'textfield',
							" . $back . "
							value:\"" . (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']]))) . "\",
                                cls:'Wdate',
							fieldLabel:'" . $value['name'] . "',
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							" . (($value['width']) ? ("width:" . $value['width'] . ",") : ("")) . "
							disabledDays :[" . @implode(',', $config['pbxq']) . "],
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							" . (($config['zwxs']) ? ("readOnly:'true',") : ("")) . "
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							//" . (($config['zqgs']) ? ("format:'" . $config['zqgs'] . "',") : ("")) . "
							name: '" . $value['fname'] . "',
                                listeners:{
                                    focus:function(){
                                        WdatePicker({dateFmt:'{$config['mygs']}'})
                                    }
                                }
							}";
                            break;
                        }
                    case 'swfupload': {
                            $js[] = "{
							xtype: '{$value['type']}',
							" . $back . "
			                name: '{$value['fname']}',
			                id: '{$value['fname']}',
			                fieldLabel: '{$value['name']}',
			                anchor:'99%',
			                height: {$config['height']}
						}";
                            break;
                        }
                    case 'combo': {
                            $tempxx = json_decode($value['zyz'], true);
                            $config_num = count($tempxx);
                            $items = '';
                            if ($config_num != 0) {
                                foreach ($tempxx as $key => $data) {
                                    if ($data['ck'] == '1') {
                                        $fdada[$value['fname']] ? $fdada[$value['fname']] : $fdada[$value['fname']] = $data['xv'];
                                    }
                                    $items.= "['" . $data['xv'] . "','" . $data['yv'] . "']";
                                    if ($key < $config_num - 1) {
                                        $items.= ",";
                                    }
                                }
                            }
                            $js[] = "{
							" . $back . "
							value:\"" . (grv($value['qzfs'], $value['blm'], adxx($fdada[$value['fname']]))) . "\",
							fieldLabel:'" . $value['name'] . "',
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							" . (($value['width']) ? ("width:" . $value['width'] . ",") : ("")) . "
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							" . (($config['readonly']) ? ("readOnly:'true',") : ("")) . "
							typeAhead: true,
							name: '" . $value['fname'] . "_',
							hiddenName : '" . $value['fname'] . "',
							editable: false,xtype: 'combo',
							store:new Ext.data.SimpleStore({
											fields:['name','value'],
											data:[" . $items . "]}),
							mode:'local',
					        displayField:'name',
					        selectOnFocus:true,
					        valueField :'value',
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
					        triggerAction:'all'

							}";
                            break;
                        }
                    case 'combo1': {
                            $listeners = '';
                            /**
                             * 动态级联 事件
                             */
                            if ($dtjl[$value['fname']] != '') {
                                $listeners = <<<EQT
                                listeners:{
                                    select:function(a,b,c){
EQT;
                                foreach ($dtjl[$value['fname']] as $d_k => $d_v) {
                                    $listeners .= <<<EQT
                                        \n\t\t\t\t\t\t Ext.getCmp('{$d_v['field']}_').setValue('');
                                        \n\t\t\t\t\t\t Ext.getCmp('{$d_v['field']}_').store.baseParams['custom[{$d_v['field2']}]'] = b.get('id');
                                        \n\t\t\t\t\t\t Ext.getCmp('{$d_v['field']}_').store.reload();
EQT;
                                }
                                $listeners .= <<<EQT
                                    \n\t\t\t\t\t}
                                },
EQT;
                            }

                            /**
                             * 动态级联 默认下拉值
                             */
                            $baseParams = '';
                            if ($dtjl_default[$value['fname']]) {
                                $baseParams = <<<EQT
                                \n\t\t\t\t\t\t\t\t Ext.getCmp('{$value['fname']}_').store.baseParams['custom[{$dtjl_default[$value['fname']]['field2']}]'] = Ext.getCmp('{$dtjl_default[$value['fname']]['field']}_').getValue()
EQT;
                            }

                            $js[] = "{
							" . $back . "
							value:\"" . (adxx($fdada[$value['fname']]) !== '' ? adxx($fdada[$value['fname']]) : $config['dy']) . "\",
							fieldLabel:'" . $value['name'] . "',
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							" . (($value['width']) ? ("width:" . $value['width'] . ",") : ("")) . "
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							" . (($config['readonly']) ? ("readOnly:'true',") : ("")) . "
							typeAhead: true,
							emptyText:'" . $config['dx'] . "',
							name: '" . $value['fname'] . "_',
							id: '" . $value['fname'] . "_',
							hiddenName : '" . $value['fname'] . "',
							editable: false,xtype: 'combo',
							store:new Ext.data.Store({
								proxy: new Ext.data.HttpProxy({
									url: '../cascade/getcascade.php?id=" . $value['id'] . "'
								}),
								listeners : {
                                beforeload :function(){
                                           {$baseParams}
                                },
								load : function(){
										if(typeof(chuzai_{$value['id']})=='undefined'){
											Ext.getCmp('" . $value['fname'] . "_" . "').setValue('" . (adxx($fdada[$value['fname']]) ? adxx($fdada[$value['fname']]) : $config['dy']) . "');
											chuzai_{$value['id']}=1;
											}
										}
										} ,
								autoLoad:true,
								reader: new Ext.data.ArrayReader({
							}, [
								{name: '" . $config['y'] . "', mapping: '" . $config['y'] . "'},
								{name: '" . $config['x'] . "', mapping: '" . $config['x'] . "'}
							])
}),
							mode:'local',
					        displayField:'" . $config['x'] . "',
					        selectOnFocus:true,
                            {$listeners}
					        valueField :'" . $config['y'] . "',
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
					        triggerAction:'all'

							}";
                            break;
                        }
                    case 'combo2': {

                            $js[] = "{
							" . $back . "
							value:\"" . (adxx($fdada[$value['fname']]) ? adxx($fdada[$value['fname']]) : $config['dy']) . "\",
							fieldLabel:'" . $value['name'] . "',
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							" . (($value['width']) ? ("width:" . $value['width'] . ",") : ("")) . "
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							" . (($config['readonly']) ? ("readOnly:'true',") : ("")) . "
							typeAhead: true,
							" . (($value['zy']) ? ("emptyText:'" . $config['x2'] . "',") : ("emptyText:'" . $config['x1'] . "',")) . "
							name: '" . $value['fname'] . "_',
							id: '" . $value['fname'] . "_',
							hiddenName : '" . $value['fname'] . "',
							editable: false,xtype: 'combo',
							store:new Ext.data.Store({
								proxy: new Ext.data.HttpProxy({
									url: '" . (($config['zy']) ? (($fdada[$config['jlzd']]) ? ("../cascade/getcascade.php?op=sort&id=" . $fdada[$config['jlzd']] . "") : ("")) : ("../cascade/getcascade.php?op=sort&id=" . $config['pid'] . "")) . "'
								}),
								listeners : {
								load : function(){
							" . (($config['zy']) ? ("if(typeof(chuzai1)=='undefined'){
											Ext.getCmp('" . $value['fname'] . "_" . "').setValue('" . (adxx($fdada[$value['fname']]) ? adxx($fdada[$value['fname']]) : $config['y2']) . "');
											chuzai1=1;
											}
										} ") : ("if(typeof(chuzai)=='undefined'){
											Ext.getCmp('" . $value['fname'] . "_" . "').setValue('" . (adxx($fdada[$value['fname']]) ? adxx($fdada[$value['fname']]) : $config['y1']) . "');
											chuzai=1;
											}
										} ")) . "

										} ,
								autoLoad:true,
								reader: new Ext.data.ArrayReader({
							}, [
								{name: 'id', mapping: 'id'},
								{name: 'title', mapping: 'title'}
							])
}),
							mode:'local',
					        displayField:'title',
					        selectOnFocus:true,
					        valueField :'id',
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
					        triggerAction:'all'
							" . (($config['zy']) ? ("") : (",
							listeners:{
								select : function(combo, record,index){
								Ext.getCmp('" . $config['jlzd'] . "_" . "').store.proxy= new Ext.data.HttpProxy({url: '../cascade/getcascade.php?op=sort&id=' + combo.value});   								Ext.getCmp('" . $config['jlzd'] . "_" . "').store.load();			Ext.getCmp('" . $config['jlzd'] . "_" . "').setValue('');

								}
								}")) . "


							}";
                            break;
                        }
                    case 'combo3': {
                            $url = '';
                            $chuzai = '';
                            $select = '';
                            switch ($config['jb']) {
                                case 1: {
                                        $url = "../cascade/getcascade.php?op=sort&id=" . $config['pid'];
                                        $chuzai = "if(typeof(chuzai1)=='undefined'){
											Ext.getCmp('" . $value['fname'] . "_" . "').setValue('" . (adxx($fdada[$value['fname']]) ? adxx($fdada[$value['fname']]) : $config['y']) . "');
											chuzai1=1;
											}";
                                        $select = " Ext.getCmp('" . $config['jl1'] . "_" . "').store.proxy= new Ext.data.HttpProxy({url: '../cascade/getcascade.php?op=sort&id='+combo.value}); Ext.getCmp('" . $config['jl1'] . "_" . "').store.load();
									 Ext.getCmp('" . $config['jl2'] . "_" . "').store.proxy= new Ext.data.HttpProxy({url: '../cascade/getcascade.php?op=kong'}); Ext.getCmp('" . $config['jl2'] . "_" . "').store.load();
								Ext.getCmp('" . $config['jl1'] . "_" . "').setValue('');
								Ext.getCmp('" . $config['jl2'] . "_" . "').setValue(''); ";
                                        break;
                                    }
                                case 2: {
                                        $url = $fdada[$config['jl1']] ? "../cascade/getcascade.php?op=sort&id=" . $fdada[$config['jl1']] : "";
                                        $chuzai = "if(typeof(chuzai2)=='undefined'){
											Ext.getCmp('" . $value['fname'] . "_" . "').setValue('" . (adxx($fdada[$value['fname']]) ? adxx($fdada[$value['fname']]) : $config['y']) . "');
											chuzai2=1;
											}";
                                        $select = " Ext.getCmp('" . $config['jl2'] . "_" . "').store.proxy= new Ext.data.HttpProxy({url: '../cascade/getcascade.php?op=sort&id=' + combo.value}); Ext.getCmp('" . $config['jl2'] . "_" . "').store.load();
								Ext.getCmp('" . $config['jl2'] . "_" . "').setValue('');";
                                        break;
                                    }
                                case 3: {
                                        $url = $fdada[$config['jl2']] ? "../cascade/getcascade.php?op=sort&id=" . $fdada[$config['jl2']] : "";
                                        $chuzai = "if(typeof(chuzai3)=='undefined'){
											Ext.getCmp('" . $value['fname'] . "_" . "').setValue('" . (adxx($fdada[$value['fname']]) ? adxx($fdada[$value['fname']]) : $config['y']) . "');
											chuzai3=1;
											}";
                                        break;
                                    }
                            }
                            $js[] = "{
							" . $back . "
							value:\"" . (adxx($fdada[$value['fname']]) ? adxx($fdada[$value['fname']]) : $config['y']) . "\",
							fieldLabel:'" . $value['name'] . "',
							" . (($value['id']) ? ("id:'" . $value['id'] . "',") : ("")) . "
							" . (($value['width']) ? ("width:" . $value['width'] . ",") : ("")) . "
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							" . (($config['readonly']) ? ("readOnly:'true',") : ("")) . "
							typeAhead: true,
							emptyText:'" . $config['x'] . "',
							name: '" . $value['fname'] . "_',
							id: '" . $value['fname'] . "_',
							hiddenName : '" . $value['fname'] . "',
							editable: false,xtype: 'combo',
							store:new Ext.data.Store({
								proxy: new Ext.data.HttpProxy({
									url: '" . $url . "'
								}),
								listeners : {
								load : function(){
								" . $chuzai . "
								}} ,
								autoLoad:true,
								reader: new Ext.data.ArrayReader({
							}, [
								{name: 'id', mapping: 'id'},
								{name: 'title', mapping: 'title'}
							])
}),
							mode:'local',
					        displayField:'title',
					        selectOnFocus:true,
					        valueField :'id',
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
					        triggerAction:'all',
							listeners:{
								select : function(combo, record,index){" . $select . "}
								}
							}";
                            break;
                        }
                    case 'radiogroup': {
                            $tempxx = json_decode($value['zyz'], true);
                            $config_num = count($tempxx);
                            if ($config_num != 0) {
                                $items = '';
                                if ($_GET['id'] != '') {
                                    foreach ($tempxx as $key => $data) {
                                        if ($data['yv'] == $fdada[$value['fname']]) {
                                            $items.= "{boxLabel:'" . $data['xv'] . "',name:'" . $value['fname'] . "',inputValue:'" . $data['yv'] . "',checked: true}";
                                        } else {
                                            $items.= "{boxLabel:'" . $data['xv'] . "',name:'" . $value['fname'] . "',inputValue:'" . $data['yv'] . "'}";
                                        }
                                        if ($key < $config_num - 1) {
                                            $items.= ",";
                                        }
                                    }
                                } else {
                                    foreach ($tempxx as $key => $data) {
                                        if ($data['ck'] == '1') {
                                            $items.= "{boxLabel:'" . $data['xv'] . "',name:'" . $value['fname'] . "',inputValue:'" . $data['yv'] . "',checked: true}";
                                        } else {
                                            $items.= "{boxLabel:'" . $data['xv'] . "',name:'" . $value['fname'] . "',inputValue:'" . $data['yv'] . "'}";
                                        }
                                        if ($key < $config_num - 1) {
                                            $items.= ",";
                                        }
                                    }
                                }
                            }
                            $js[] = "{
							xtype: 'radiogroup',
							" . $back . "
							" . (($value['width'] && $value['width'] <= $config_num) ? ("columns:" . $value['width'] . ",") : ("")) . "
							" . (($config['vertical']) ? ("vertical: true,") : ("")) . "
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							anchor: '95%',
							 items: [" . $items . "],
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							fieldLabel:'" . $value['name'] . "'
							}";
                            break;
                        }
                    case 'recommend': {
                            $items = '';
                            $bs0 = '不推荐';
                            $bs1 = '推荐中';
                            if ($config['bs0'] != '' && $config['bs1'] != '') {
                                $bs0 = $config['bs0'];
                                $bs1 = $config['bs1'];
                            }
                            if (0 < $fdada[$value['fname']]) {
                                $recommend_val = $fdada[$value['fname']] != '' && $fdada[$value['fname']] != 0 ? $fdada[$value['fname']] : 1;
                                $items.= "{boxLabel:'{$bs1}',name:'" . $value['fname'] . "',inputValue:'{$fdada[$value['fname']]}',checked: true},";
                                $items.= "{boxLabel:'{$bs0}',name:'" . $value['fname'] . "',inputValue:'0'}";
                            } else {
                                $recommend_val = $fdada[$value['fname']] != '' && $fdada[$value['fname']] != 0 ? $fdada[$value['fname']] : 1;
                                if ($config['mr'] == 1 && $_GET['id'] == "") {
                                    $items.= "{boxLabel:'{$bs1}',name:'" . $value['fname'] . "',inputValue:'{$recommend_val}',checked: true},";
                                    $items.= "{boxLabel:'{$bs0}',name:'" . $value['fname'] . "',inputValue:'0'}";
                                } else {
                                    $items.= "{boxLabel:'{$bs1}',name:'" . $value['fname'] . "',inputValue:'{$recommend_val}'},";
                                    $items.= "{boxLabel:'{$bs0}',name:'" . $value['fname'] . "',inputValue:'0',checked: true}";
                                }
                            }

                            $js[] = "{
							xtype: 'radiogroup',
							" . $back . "
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							anchor: '95%',
							 items: [" . $items . "],
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							fieldLabel:'" . $value['name'] . "'
							}";
                            break;
                        }
                    case 'checkboxgroup': {
                            $tempxx = json_decode($value['zyz'], true);
                            $config_num = count($tempxx);
                            if ($config_num != 0) {
                                $items = '';
                                if ($_GET['id'] != '') {
                                    $xsarray = explode("#_#", $fdada[$value['fname']]);
                                    foreach ($tempxx as $key => $data) {
                                        if (in_array($data['yv'], $xsarray)) {
                                            $items.= "{boxLabel:'" . $data['xv'] . "',name:'" . $value['fname'] . "[" . $key . "]',inputValue:'" . $data['yv'] . "',checked: true}";
                                        } else {
                                            $items.= "{boxLabel:'" . $data['xv'] . "',name:'" . $value['fname'] . "[" . $key . "]',inputValue:'" . $data['yv'] . "'}";
                                        }
                                        if ($key < $config_num - 1) {
                                            $items.= ",";
                                        }
                                    }
                                } else {
                                    foreach ($tempxx as $key => $data) {
                                        if ($data['ck'] == '1') {
                                            $items.= "{boxLabel:'" . $data['xv'] . "',name:'" . $value['fname'] . "[" . $key . "]',inputValue:'" . $data['yv'] . "',checked: true}";
                                        } else {
                                            $items.= "{boxLabel:'" . $data['xv'] . "',name:'" . $value['fname'] . "[" . $key . "]',inputValue:'" . $data['yv'] . "'}";
                                        }
                                        if ($key < $config_num - 1) {
                                            $items.= ",";
                                        }
                                    }
                                }
                            }
                            $js[] = "{
							xtype:'checkboxgroup',
							" . $back . "
							" . (($value['width'] && $value['width'] <= $config_num) ? ("columns:" . $value['width'] . ",") : ("")) . "
							" . (($config['vertical']) ? ("vertical: true,") : ("")) . "
							" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
							anchor: '95%',
							 items: [" . $items . "],
							" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
							fieldLabel:'" . $value['name'] . "'
							}";
                            break;
                        }
                    case 'checkboxgroup1': {
                            $tempxx = Dgs("{$config['table']}", "{$config['conditon']}");
                            $config_num = count($tempxx);
                            if ($config_num != 0) {
                                $items = '';
                                if ($_GET['id'] != '') {
                                    $xsarray = explode("#_#", $fdada[$value['fname']]);
                                    foreach ($tempxx as $key => $data) {
                                        if (in_array($data[$config['y']], $xsarray)) {
                                            $items.= "{boxLabel:'" . $data[$config['x']] . "',name:'" . $value['fname'] . "[" . $key . "]',inputValue:'" . $data[$config['y']] . "',checked: true}";
                                        } else {
                                            $items.= "{boxLabel:'" . $data[$config['x']] . "',name:'" . $value['fname'] . "[" . $key . "]',inputValue:'" . $data[$config['y']] . "'}";
                                        }
                                        if ($key < $config_num - 1) {
                                            $items.= ",";
                                        }
                                    }
                                } else {    //添加的时候
                                    foreach ($tempxx as $key => $data) {
                                        $items.= "{boxLabel:'" . $data[$config['x']] . "',name:'" . $value['fname'] . "[" . $key . "]',inputValue:'" . $data[$config['y']] . "'}";
                                        if ($key < $config_num - 1) {
                                            $items.= ",";
                                        }
                                    }
                                }
                            }
                            $js[] = "{
					xtype:'checkboxgroup',
					" . $back . "
					" . (($value['width'] && $value['width'] <= $config_num) ? ("columns:" . $value['width'] . ",") : ("")) . "
					" . (($config['vertical']) ? ("vertical: true,") : ("")) . "
					" . ((!$value['yxwk']) ? ("allowBlank:false,blankText:'" . adxx($value['ts']) . "',") : ("")) . "
					anchor: '95%',
					items: [" . $items . "],
					" . (($config['STR']) ? ("" . $config['STR'] . "") : ("")) . "
					fieldLabel:'" . $value['name'] . "'
				}";
                            break;
                        }
                    default: {
                            $js[] = "{
							xtype: 'textfield',
							fieldLabel: '{$value['name']}',
							name: '{$value['fname']}',
							" . $back . "
							anchor:'60%'
						}";
                        }
                }
            }
            Tr($plugurl, 'plugurl');
            Tr($plugjs, 'plugjs');
            Tr($fckplugin, 'fckplugin');
            Tr($js, 'js');
            if ($_GET['id'] == 0) {
                Tr('添加', 'action');
            } else {
                Tr('编辑', 'action');
            }
            Ts('show1/add.html');
            break;
        }
    case 'save': {

            $id = $_POST['id'];
            $tree_id = $_POST['tid'];
            $tree = Dgd(array(
                'db' => 'd_sevenel',
                'cd' => "id = $tree_id",
                'tn' => "tree",
                'limit' => '1'
                    ));
            $tabname = gettabname($tree['table'], '', true);
            $fld = Dgd(array(
                'db' => 'd_sevenel',
                'cd' => "tid = $tree_id  and del!=1",
                'tn' => "fld"
                    ));
            foreach ($fld as $key => $value) {
                switch ($value['type']) {
                    case 'datefield':
                    case 'my97': {
                            if ($value['zy'] != 1) {
                                if (strtotime($_POST[$value['fname']])) {
                                    $save[$value['fname']] = strtotime($_POST[$value['fname']]);
                                } else {
                                    $save[$value['fname']] = $_POST[$value['fname']];
                                }
                            } else {
                                $save[$value['fname']] = $_POST[$value['fname']];
                            }
                            break;
                        }
                    case 'checkboxgroup': {
                            $save[$value['fname']] = implode("#_#", $_POST[$value['fname']]);
                            break;
                        }
                    case 'checkboxgroup1': {
                            $save[$value['fname']] = implode("#_#", $_POST[$value['fname']]);
                            break;
                        }
                    case 'password';
                        {
                            if ($value['yxwk'] == '1') {
                                if ($_POST[$value['fname']] == $_POST[$value['fname'] . '-cfrm']) {
                                    $save [$value['fname']] = md5($_POST[$value['fname']]);
                                } else {
                                    ext_request_failure('两次输入不相同');
                                    exit();
                                }
                            } else {
                                $save [$value['fname']] = md5($_POST[$value['fname']]);
                            }
                            break;
                        }
                    case 'fileup': {
                            //print_r($_FILES);exit;
                            if ($_FILES[$value['fname']]['name'] != '') {
                                $cp = 1;
                                //复制文件
                                $config = json_decode($value['cfg'], true);

                                $config['sclj'] || $config['sclj'] = 'pic';



                                $dvalue = array(0 => array('rar', 'zip', 'tar', '.tz'),
                                    1 => array('jpg', 'gif', 'png', 'bmp'),
                                    2 => array('mp3', 'mp4', 'avi', 'wmv', 'mid', '.rm', 'mvb', 'mov', 'wma', 'wav'),
                                    3 => array('doc', 'xls', 'txt', 'ocx', 'lsx', 'ppt', 'pdf', 'chm'),
                                    4 => false
                                );
                                if (!$_FILES[$value['fname']]['name']) {
                                    $cp = 0;
                                }
                                /**
                                 * 解决后缀问题
                                 * 2011-8-18    Bic
                                 */
                                $otype = trim(end(explode('.', strtolower($_FILES[$value['fname']]['name']))));

                                if ($dvalue[$config['type']] !== false && !in_array($otype, $dvalue[$config['type']])) {
                                    $cp = 0;
                                    header("Content-type: text/html; charset: UTF-8");
                                    echo "{success:true,msg:'%u4E0A%u4F20%u683C%u5F0F%u4E0D%u5141%u8BB8%21%u8BF7%u8054%u7CFB%u7BA1%u5458%21<BR> Upload format is not allowed! Please contact the administrator!'}";
                                    exit;
                                }
                                if ($_FILES[$value['fname']]['size'] / 1000 > $config['size']) {
                                    $cp = 0;
                                    header("Content-type: text/html; charset: UTF-8");
                                    echo "{success:true,msg:'%u6587%u4EF6%u5927%u5C0F%u8D85%u8FC7%u9650%u5236%21<br> The file size limit expired!'}";
                                    exit;
                                }
                                if ($cp) {
                                    $bsname = time() . rand(10000, 999999);
                                    $bcname = $bsname . "." . $otype;
                                    $filename = "../../uplods/{$config['sclj']}/" . $bcname;
                                    $copymes = copy($_FILES[$value['fname']]['tmp_name'], $filename);
                                    $save[$value['fname']] = $bcname;
                                }
                                if (in_array($otype, $dvalue[1])) {
                                    if ($config['sl1'] == 1) {
                                        @createthumb($_FILES[$value['fname']]['tmp_name'], "." . $otype, $bsname, $config['sl1x'], $config['sl1y'], '1');
                                    }
                                    if ($config['sl2'] == 1) {
                                        @createthumb($_FILES[$value['fname']]['tmp_name'], "." . $otype, $bsname, $config['sl2x'], $config['sl2y'], '2');
                                    }
                                    if ($config['sypic'] == 1) {
                                        $sypicname = "../../uplods/sypic/" . $bcname;
                                        $sypicwz = "../../uplods/" . $config['sytp'] . "";

                                        //echo $sypicwz ,$config['sytp'],$config['sywz'];
                                        @imageWaterMark($filename, $sypicname, $config['sypicwz'], $sypicwz, "", 20, 'wqy-microhei-lite.ttc', "#00FF00");
                                    }
                                    if ($config['sytxt'] == 1) {
                                        $sypicname = "../../uplods/sytxt/" . $bcname;
                                        $sypicwz = "";
                                        @imageWaterMark($filename, $sypicname, $config['sytxtwz'], "", $config['sywz'], $config['sywzdx'], $config['syzt'], "#" . $config['syys']);
                                    }
                                    if ($config['sytxt'] == 1 && $config['sypic'] == 1) {
                                        $filename = "../../uplods/sypic/" . $bcname;
                                        $sypicname = "../../uplods/sytp/" . $bcname;
                                        $sypicwz = "";
                                        @imageWaterMark($filename, $sypicname, $config['sytxtwz'], "", $config['sywz'], $config['sywzdx'], $config['syzt'], "#" . $config['syys']);
                                    }
                                }
                                $del_file[] = $value['fname'];
                            }
                            break;
                        }
                    default: {
                            $save[$value['fname']] = $_POST[$value['fname']];
                        }
                }
            }
            $save['tid'] = $tree_id;
            !$_POST['lg'] && $save['lg'] = 'zh';
            $_POST['bdid'] && $save['bdid'] = $_POST['bdid'];
            $_POST['bdtid'] && $save['bdtid'] = $_POST['bdtid'];
            !$_POST['gid'] && $save['gid'] = Mct();
            $save['at'] = time();
            if ($id != 0) {

                /**
                 * 删除老的已上传的文件
                 * 2011-8-18    Bic
                 */
                $tmp = Dgd(array(
                    'db' => 'd_sevenel',
                    'cd' => "id = {$id}",
                    'tn' => $tabname,
                    'limit' => 1
                        ));
                foreach ($del_file as $v) {
                    unlink("../../uplods/{$config['sclj']}/{$tmp[$v]}");
                }

                if (Du('sevenel', $tabname, $save, 'id', $id)) {
                    $save['opid'] = $id;
                    $plugin = Plugin::init();
                    $plugin->trigger('show1_du_after', $save);
                    ext_request('ok');
                }
            } else {
                if (Di('sevenel', $tabname, $save)) {
                    $plugin = Plugin::init();
                    $plugin->trigger('show1_di_after', $save);
                    ext_request('ok');
                }
            }
            break;
        }
    case 'qkzd': {
            //删除老图片

            $tmp = Dgd(array(
                'db' => 'd_sevenel',
                'cd' => "id = {$_POST['id']}",
                'tn' => $_POST['tname'],
                'limit' => 1
                    ));
            if ($tmp[$_POST['zd']] != '') {

                //图片地址
                $tmp_fld = Dga('fld', "del!=1 and fname='{$_POST['zd']}' and tid='{$tmp['tid']}'");
                $config = json_decode($tmp_fld['cfg'], true);
                $config['sclj'] || $config['sclj'] = 'pic';

                unlink("../../uplods/{$config['sclj']}/{$tmp[$_POST['zd']]}");
            }

            $save[$_POST['zd']] = '';
            if (Du('sevenel', $_POST['tname'], $save, 'id', $_POST['id'], 1))
                ext_request('ok'); break;
        }
    case 'gxzd': {
            $save[$_POST['zd']] = $_POST['xz'];
            if (Du('sevenel', $_POST['tname'], $save, 'id', $_POST['id'], 1))
                ext_request('ok'); break;
        }
}
?>